/**
 * Author: Dmitry Ustimov
 * Date: 6/2/13
 * Time: 1:19 AM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.classic.work.demo.handlers6_requests5;

public abstract class Handler {

    private Handler next;

    public void setNext(Handler successor) {
        this.next = successor;
    }

    public abstract Boolean canHandle(Request request);

    public abstract void doAction(Request request);

    public void handle(Request request) {
        if (canHandle(request)) {
            doAction(request);
        }
        else {
            if (next != null) {
                next.handle(request);
            }
        }
    }

    public void handleChain(Request request) {
        if (canHandle(request)) {
            doAction(request);
        }
        if (next != null) {
            next.handleChain(request);
        }
    }
}
